import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

const files = require.context('./modules', false, /\.js$/)
const modules = {}

files.keys().forEach((key) => {
  const modelesKey = key.replace(/(\.\/|\.js)/g, '')
  modules[modelesKey] = files(key).default
  modules[modelesKey]['namespaced'] = true
})

const store = new Vuex.Store({
  modules,
  getters
})

export default store
